import React from 'react'
import { connect } from 'dva'
import ProductList from '../../components/ProductList'

const Products = (props) => {
  const {
    products,
    handleDelete
  } = props

  return (
    <div>
      <div>List of Products</div>
      <ProductList onDelete={handleDelete} products={products}/>
    </div>
  )
}
const mapStateToProps = (state) => {
  return {
    products: state.products.products
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    handleDelete: (id) => {
      dispatch({
        type: 'products/delete',
        payload: id
      })
    }
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(Products)

